/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.Order;
import ecommerce.model.Payment;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Hadi
 */
@Repository
public class PaymentDao {
    @Autowired private SessionFactory sessionFactory;

    public void save(Payment o){
        sessionFactory.getCurrentSession().saveOrUpdate(o);
    }

    public void delete(Payment o){
        sessionFactory.getCurrentSession().delete(o);
    }

    public Payment findById(Long id){
        return (Payment) sessionFactory.getCurrentSession().get(Payment.class, id);
    }

    public List<Payment> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from Payment").list();
    }
}
